package codebush.test.learn.dataPersistence;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * jdbc connect to a mysql database 2008-5-8
 * 
 * @author Fution Bai Copyright 2007
 */

public class JdbcConnectToMysql {
	public static void main(String[] args) {
		try {
			// Step 1: Load the JDBC driver.
			Class.forName("com.mysql.jdbc.Driver");
			// Step 2: Establish the connection to the database.
			String url = "jdbc:mysql://localhost:3306/codebush";
			Connection conn = DriverManager.getConnection(url, "root", "");
			Statement st = conn.createStatement();
			st.setFetchSize(5);
			ResultSet rs = st.executeQuery("select * from tag;");
			
			rs.setFetchSize(6);
			int count = st.getFetchSize();
			System.out.println("count " + count);
			while (rs.next()) {
				System.out.println(rs.getInt(1));
			}
		} catch (Exception e) {
			System.err.println("Got an exception! ");
			System.err.println(e.getMessage());
		}
	}
}
